﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;
using Kristall.Engine;

namespace Kristall.MyGame.Projectiles
{
    public class TestProjectile : Projectile
    {
        public AnimatableSprite defaultAnimation;

        static string defaultKey = @"Projectiles\Test.xnb";

        Light _light;

        public override string ImpactSoundCue
        {
            get
            {
                return "PlasmaLauncherImpact";
            }
        }

        public override Vector2 Center
        {
            get
            {
                return base.Center;
            }
            set
            {
                base.Center = value;
                _light.Center = value;
            }
        }

        public TestProjectile(AABB host = null) : base(host)
        {
            Kristall.SoundManager.PlayNonInstancedSound("Fire");
        }

        public override void LoadContent(Level level)
        {
            Damage = 0.25f;
            Speed = 600.0f;
            LifeSpan = 2.0f;
            Width = Height = 16;

            defaultAnimation = new AnimatableSprite(defaultKey);
            defaultAnimation.FrameWidth = defaultAnimation.FrameHeight = 32;
            defaultAnimation.Scale = Vector2.One * 0.5f;

            Animations.Add(defaultAnimation);
            CurrentAnimationKey = defaultKey;

            _light = new Light();
            _light.Color = Color.White;
            _light.Width = 32;
            _light.Height = 32;
            level.Lights.Add(_light);

            base.LoadContent(level);
        }

        public override void Update(float dt)
        {
            base.Update(dt);

            if (IsAlive)
            {
                _light.Center = this.Center;
            }
            else
            {
                Level.Lights.Remove(_light);
            }
        }

    }
}
